<?php
		  
	include ("Outils.inc");
	require ("connect.php");	
		  
	if ( !isset($_COOKIE['identite']) ) {
		  $Nom = ($_POST['Nom']);
		  $Code = ($_POST['Code']);
		  $mois = 60 * 60 * 24 * 30;

		 identification($Nom, $Code, $serv, "IdentificationC.php");
		 //la fonction identification quitte si l'identification a �chou�
		 
		  	setcookie('identite[0]', "$Nom", time()+ $mois);
			setcookie('identite[1]', "$Code", time()+ $mois);
			$cookieEnvoye = true;
	}
	else {
		$cookieEnvoye = true;
		$identite = $_COOKIE['identite'];
		$Nom = $identite[0];
		$Code = $identite[1];

	}
		  
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css" media="screen">@import "style.css";</style>

<title> VideoExpress - PHP Projet</title>

<SCRIPT TYPE="text/javascript">

function popupform(myform, windowname)
{
if (! window.focus)return true;
window.open('', windowname, 'height=500,width=1000,scrollbars=yes');
myform.target=windowname;
return true;
}

</SCRIPT>


</head>

<body>
<div class="center">
<div class="outer" id="outer">
<div class="outer_l">
<div class="outer_r">

<!--ENTETE & MENU-->
<?php 
banniere("VideoExpress","Nguyen Tat Son Tung",$cookieEnvoye);
?>
<!--FIN ENTETE & MENU-->


<!--CONTENT-->
<div class="wrap main_content_max" id="main_content">
<div class="content">
<table class="blog" cellpadding="0" cellspacing="0">
<tr><td valign="top"><div>
		
<table class="contentpaneopen"><tr>
<td class="contentheading" width="100%">COMMANDE DE CASSETTES</td></tr></table>
<table class="contentpaneopen"><tr><td valign="top" colspan="2">
<?php

/* Mise à jour les films réservee qui dépasse le temps de réservation */

$update="UPDATE `cassettes`
SET `Statut` = 'disponible'
WHERE `Statut` = 'reservee'
AND EXISTS 
(SELECT *
FROM `empres`  
	WHERE (TIMEDIFF(NOW(), `DateEmpRes`) > '00:00:10' ))";

DB_execSQL($update,$serv);

/* Mise a jour le table empres pour les films disponibles */


$del="DELETE FROM `empres`
WHERE EXISTS
(SELECT `cassettes`.`NoFilm`, `cassettes`.`NoExemplaire`
FROM `cassettes`
WHERE `empres`.`NoFilm` = `cassettes`.`NoFilm`
AND `empres`.`NoExemplaire` = `cassettes`.`NoExemplaire`
AND `cassettes`.`Statut` = 'disponible')";

DB_execSQL($del,$serv);



$req1="SELECT *"
	."FROM `abonnes`"
	."WHERE `Code` LIKE '$Code'"
	."AND `Nom` LIKE '$Nom'";
	 
$resul1 = DB_execSQL($req1,$serv);
$count = mysql_num_rows($resul1);

if ( $count == 0 ) {
echo '<img src="images/Cancel2.png"> <br \>';
echo "<font size='2'>Vous n'�tes pas reconnu <br \>"
	."Veuillez verifier votre nom d'abonn� et votre mot de passe" 	."</font><br \>";
include ("inc/inc-abonne.php");
}else {

while ($abonne = mysql_fetch_object($resul1)){

if ( $abonne->NbCassettes >= 3 ) {
echo "<table><tr><td><img src='images/shopping_cart_remove.png'><br \></td>
	<td><div align='right'>
	<form method='POST' action='Deconnecte.php' \">
Deconnect&eacute; <input type='image' src='images/deconnect.ico' alt='Deconnecte'>
</form></td></tr></table><br \>"; 
echo "<font size='2'>Vous n'avez pas de droite de commander des cassettes. <br \><br \><br \>"
	."Votre cassettes d&eacute;tenues maximum est 3</font><br \> <br \><br \>";
echo "<form method='POST' action='Detenues.php' onSubmit=\"popupform(this, 'join')\">
Cliquez ici pour voir vos cassettes d&eacute;tenues  <input type='submit' value='Cliquez-moi' STYLE='font-family:Garamond; font-size:medium;
font-style:normal; background:#444444 none; color:#FFF; border: 1px dotted'>
</form>";

} else {

$num = $abonne->NbCassettes;
$pass = "$abonne->Code";
$maxi = 3 - $num;
echo "<table><tr><td><img src='images/shopping_cart.png'><br \></td>
	<td><div align='right'>
	<form method='POST' action='Deconnecte.php' \">
Deconnecte <input type='image' src='images/deconnect.ico' alt='Deconnecte'>
</form></td></tr></table><br \>"; 

echo "<font size='2'>Bonjour $Nom , vous pouvez commander "
	."maximum ".$maxi." cassette(s)</font><br \>";
echo "<form method='POST' action='ConfirmeCommande.php' id='form-search'>
	<input type='HIDDEN' class='input' name='Code' value='$Code'/>
	<input type='HIDDEN' class='input' name='Nom' value='$Nom'/>
	<input type='HIDDEN' class='input' name='Max' value='$maxi'/>";
echo '<div class="jl_table">
  	<table cellpadding="3" cellspacing="0" border="1">
  	<tr class="sectiontableheader">
	<td width="40"><font size="2">NoFilm</font></td>
	<td width="40"><font size="2">Support</font></td>
	</tr>';

for ($i=1; $i<=$maxi; $i++){

echo "<TR><TD>
	<fieldset>
	<p id='inputbox'>
	<p><h2> NoFilm$i    
	<input type='NoFilm' name='NoFilm$i' class='inputbox' STYLE='font-family:Garamond; font-size:medium;
font-style:normal; background:#444444 none; color:#FFF; border: 1px dotted'>
	<TD>
	<p><h2>DVD
	<input type='radio' name='Support$i' value='DVD' checked='checked'></p>
	<p><h2>VHS
	<input type='radio' name='Support$i' value='VHS'></p>
	</fieldset>";
}


echo '</table>
	</div>
	<p><input type="submit" name="Submit" class="button" value="Valider" STYLE="font-family:Garamond; font-size:medium;
font-style:normal; background:#444444 none; color:#FFF; border: 1px dotted">
	</p>
	</form>';
}

}
} 
?>
</td></tr></table>

<span class="article_separator">&nbsp;</span>

</div></td></tr></table>
</div>
</div>
</div>
</div>
</div>
</div>
<!--FIN CONTENT-->

<!-- PIED -->
<?php include ("inc/inc-pied.php"); ?>
<!-- FIN - PIED --> 
</body>
</html>
